<?php 
/*
**模型：信息模型（未来的CMS）
**model/class.cms.php
**By QINIAO
*/

class qiCms{
	var $db;
	
	function qiCms($dbhandle)
	{
		$this->db = $dbhandle;
	}

	//获取CMS信息列表
	function getCms()
	{
	$res = $this->db->query("select * from ".DB_PREFIX."cms");
	$cmss = array();
	while($row = $this->db->fetch_array($res))
	{
	$row['cid'] = $row['cid'];
	$row['title'] = $row['title'];
	$row['content'] = $row['content'];
	$cmss[] = $row;
	}
	return $cmss;
	}
	
	//获取指定分类下的信息列表
	function getCateCms($cateid)
	{
	$res = $this->db->query("select * from ".DB_PREFIX."cms where cid = $cateid");
	$cmss =array();
	while($row = $this->db->fetch_array($res))
	{
	$row['cid'] = $row['cid'];
	$row['title'] = $row['title'];
	$row['content'] = $row['content'];
	$cmss[] = $row;
	}
	return $cmss;
	}
	
	//获取一条CMS的数据
	function getOneCms($cmsid)
	{
	$res = $this->db->query("select * from ".DB_PREFIX."cms where id=$cmsid");
	$row = $this->db->fetch_array($res);
	$cmsData = array();
	if($row)
	{
	$cmsData = array(
	'title' => $row['title'],
	'content' => $row['content']
	);
	}
	return $cmsData;
	}
	
	//添加CMS信息
	function addCms($cateid,$cmstitle,$cmscontent)
	{
	$sql = "insert into ".DB_PREFIX."cms (cid,title,content) values ('$cateid','$cmstitle','$cmscontent')";
	$this->db->query($sql);
	}
	
	//更新cms信息
	function updateCms($cmsData,$cmsid)
	{
	$Item = array();
	foreach($cmsData as $key=>$data)
	{
	$Item[] = "$key = '$data'";
	}
	$upStr = implode(',',$Item);
	$this->db->query("update ".DB_PREFIX."cms set $upStr where id=$cmsid");
	}
	
	//删除CMS信息
	function deleteCms($cmsid)
	{
	$this->db->query("delete from ".DB_PREFIX."cms where id=$cmsid");
	}
 

	}

?>